<template>
  <div class="cdkey-wrap">
    <van-nav-bar
      title="兑换码"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <div class="exchange">
      <div class="e-header">
        <p>请输入兑换码</p>
        <img src="../assets/image/saoma.png" alt="" />
      </div>
      <div>
        <van-field
          v-model="digit"
          type="digit"
          maxlength="10"
          size="large"
          input-align="center"
        />
      </div>
    </div>
    <div class="btn">
      <button
        class="active"
        @click="hint()"
        :class="{ actived: digit.length >= 6 }"
      >
        兑换
      </button>
    </div>
    <div class="text">
      <h4>兑换码使用规则</h4>
      <p>·请使用扫码按钮，扫描二维码进项兑换</p>
    </div>
  </div>
</template>

<script>
import { reactive, toRefs } from "@vue/reactivity";
import { Dialog } from "vant";
export default {
  setup() {
    const state = reactive({
      digit: "",
    });
    const onClickLeft = () => history.back();
    const hint = () => {
      if (state.digit.length >= 6) {
        Dialog.confirm({
          title: "提示",
          message: "是否使用此兑换码进行兑换",
        })
          .then(() => {
            Dialog.alert({
              title: "提示",
              message: "此兑换码无效，无法使用",
            });
          })
          .catch(() => {
            // on cancel
          });
      }
    };
    return {
      ...toRefs(state),
      onClickLeft,
      hint,
    };
  },
};
</script>

<style lang="less" scoped>
.cdkey-wrap {
  .exchange {
    border: 1px solid #f5f5f5;
    border-radius: 10px;
    margin: 10px;
    .e-header {
      display: flex;
      justify-content: space-between;
      p {
        margin: 30px 20px;
        color: #999;
      }
      img {
        margin: 30px 20px;
        height: 22px;
        width: 22px;
      }
    }
    .van-cell {
      line-height: 100px;
      font-size: 50px;
    }
  }
  .btn {
    .active {
      width: 94%;
      height: 55px;
      margin: 20px 10px;
      background-color: #ccc;
      border: 0;
      border-radius: 10px;
      color: #f0f0f0;
      font-size: 20px;
    }
    .actived {
      color: #fff;
      background-color: #eb1f69;
    }
  }
  .text {
    margin: 0 10px;
    h4 {
      font-size: 14px;
    }
    p {
      margin: 0;
      font-size: 18px;
    }
  }
}
</style>